<template>
	<view class="user_setting">
		<uni-list :border="false">
			<uni-list-item @click="$nav('/pagesUser/setting/person')" clickable title="个人资料" :showArrow="true"></uni-list-item>
			<uni-list-item @click="$nav('/pages/user/address/index')" clickable title="收货地址" :showArrow="true"></uni-list-item>
			<uni-list-item @click="bind" clickable title="账号绑定" :showArrow="true">
				<template slot="footer">
					<view v-if="!userInfo.wechat_check">
						<uni-icons color="rgb(80, 182, 116)" size="18" type="weixin"></uni-icons>
						<text style="color:#aaa;font-size: 28rpx;margin-left: 15rpx;">未绑定微信</text>
					</view>
					<view v-else-if="userInfo.phone == ''">
						<uni-icons color="#333" size="18" type="phone-filled"></uni-icons>
						<text style="color:#aaa;font-size: 28rpx;margin-left: 15rpx;">未绑定手机</text>
					</view>
					<view v-else>
						<uni-icons color="rgb(80, 182, 116)" size="18" type="checkbox-filled"></uni-icons>
						<text style="color:#aaa;font-size: 28rpx;margin-left: 15rpx;">已绑定</text>
					</view>
				</template>
			</uni-list-item>
		</uni-list>
		
		<uni-list :border="false" style="margin-top: 20rpx;">
			<uni-list-item @click="clearCache" clickable title="清除缓存" :showArrow="true"></uni-list-item>
			<uni-list-item @click="about()"  clickable title="关于我们" :showArrow="true"></uni-list-item>
			<uni-list-item clickable title="检查更新" rightText="当前版本 1.0.3" :showArrow="true"></uni-list-item>
		</uni-list>
		
		<view class="log-out-btn" @click="logout">退出登录</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo:{
					wechat_check:false,
					phone:'',
				},
			};
		},
		onLoad() {
			/*uni.$on('users',()=>{
				this.checkLogin();
			})
			this.checkLogin();*/ //2改
		},
		methods:{
			logout(){
				let token = uni.getStorageSync('token')
				uni.removeStorageSync('token')
				uni.$emit('users')
				this.$http(this.$api.logout,{token:token}).then(res=>{
					
				})
				uni.switchTab({
					url:'/pages/index/index'
				})
			},
			clearCache(){
				uni.showLoading({
					title:'缓存清理...'
				})
				setTimeout(()=>{
					uni.hideLoading();
					this.$toast('缓存清理完成');
				},1500)
			},
			about(){
				this.$toast('QQ群:1062159788');
			},
			bind(){
				if(!this.userInfo.wechat_check){
					return this.$nav('/pagesUser/setting/bind?type=0');
				}else if(this.userInfo.phone == ''){
					return this.$nav('/pagesUser/setting/bind?type=1');
				}
			},
			checkLogin(){
				let obj = {...this.$api.users}
				obj.url += '/info'
				this.$http(obj).then(res=>{
					if(res.code == 200){
						this.userInfo = res.data
					}
				})
			},
		}
	}
</script>

<style lang="scss">
.user_setting{
	margin-top: 20rpx;
	.log-out-btn{
		display: flex;
		align-items: center;
		justify-content: center;
		width: 690upx;
		height: 80upx;
		margin: 60upx auto;
		color: #fff;
		background-color: #ea1f22;
		border-radius: 10upx;
		box-shadow: 1px 2px 5px rgba(219, 40, 43, 0.4);	
	}
}
</style>
